/**
 * Created by dqw on 2015/12/30.
 */
//列表开始
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    {
        id: 'id',
        title: 'ID',
        type: 'int',
        columnClass: 'text-center width-50',
        fastSort: false
    },
    {
        id: 'u.userName',
        title: '用户姓名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-100',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'u.mobilePhone',
        title: '用户手机',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-100',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'billNo',
        title: '账单编号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-160',
        fastSort: true,
        hideType: 'md|sm|xs|lg'

    },
    // {
    //     id: 'type',
    //     title: '充值类型',
    //     type: 'string',
    //     headerClass: 'text-center',
    //     columnClass: 'text-center',
    //     fastSort: true,
    //     fastQuery: false
    // },
    {
        id: 'type',
        title: '充值类型',
        type: 'int',
        headerClass: 'text-center',
        columnClass: 'text-center width-100',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable:{
            1:$lang.accountRechargeType.T1,
            2:$lang.accountRechargeType.T2,
            3:$lang.accountRechargeType.T3
        },
    },
    {
        id: 'amount',
        title: '充值金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center width-90',
        fastSort: true,
        fastQuery: true,
        format:'#,###.00',
        fastQueryType: 'range'
    },
    {
        id: 'credited',
        title: '到账金额',
        type: 'int',
        headerClass: 'text-center',
        columnClass: 'text-center width-90',
        fastSort: true,
        fastQuery: false,
        format:'#,###.00',
        fastQueryType: 'lk'
    },
    {
        id: 'fee',
        title: '手续费',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-center width-70',
        fastSort: true,
        fastQuery: false,
        format:'#,###.00',
        fastQueryType: 'lk'
    },
    {
        id: 'bearparty',
        title: '承担方',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center width-100',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable:{
            1:$lang.PartyBear.T1,
            2:$lang.PartyBear.T2
            // 3:$lang.bearParty.other,
        },
    },
    {
        id: 'status',
        title: '状态',
        type: 'string',
        headerClass: 'text-center width-100',
        columnClass: 'text-center',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable:{
            1:$lang.rechargeStatus.T1,
            2:$lang.rechargeStatus.T2,
            3:$lang.rechargeStatus.T3,
            4:$lang.rechargeStatus.T4
        },
    },
    {
        id: 'remark',
        title: '备注',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'lk',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'billNo',
        title: '充值编号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'createTime',
        title: '充值时间',
        type: 'date',
        format:'yyyy-MM-dd',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'range'
    },
    {
        id: 'orderNo',
        title: '第三方流水号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'lk',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'operation',
        title: '管理操作',
        type: 'string',
        columnClass: 'text-center width-100',
        fastSort: false,
        extra: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var verify = "<a data-target='#addModal2' class='btn btn-sm btn-primary m-r-10' data-toggle='modal' data-no='" + dataNo + "'><i class='fa fa-edit'></i>&nbsp;审核&nbsp;</a>";
            var html = "";
            if (record.type == "支付宝转账" || record.type == "微信转账" || record.type == "银行转账") {
                if (record.status == 1){

                    // 判断是否有编辑权限
                    if ($("#verifyPermi") && $("#verifyPermi").val() == 1) {
                        html += verify;
                    }
                }
            }
            return html;
        }
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'recharge/list.json',
    exportURL:ncGlobal.adminRoot + 'recharge/export.json',
    exportFileName: '充值记录列表',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {int:["id","bearparty","status","userId"],Timestamp:["createTime"],BigDecimal:["credited","amount","fee"]},
    tools:'refresh|faseQuery|export[excel]',
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;

//排序
grid.sortParameter.columnId = ['asc_id'];
// grid.sortParameter.sortType = 1;
//列表结束

//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {

        //新增对话框初始化
        $("#addModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#addForm").psly().reset();

            $.each($("#addForm input"),function (i, v) {
                $(v).val('');
            })
        });

        //编辑对话框初始化
        $("#editModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#editForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var datano = button.data('no');
            var modal = $(this);
            //获取列表框中的原始数据
            var gridData = grid.sortOriginalDatas[datano];
            investAccount = gridData.investAccount;

            $("#investId").val(gridData.id);
            $("#adminName").val(gridData.name);
            modal.find("[name='password']").val("");
            modal.find("[name='password2']").val("");
            modal.find("[name='roleId']").val(gridData.roleId);
        });
        //新增对话框初始化
        $("#addModal2").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#addForm2").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            var datano = button.data('no');
            var gridData = grid.sortOriginalDatas[datano];
            var modal = $(this);

            modal.find("[name='id']").val(gridData.id);
            modal.find("[name='userId']").val(gridData.userId);
            modal.find("[name='phone']").val(gridData.phone);
            modal.find("[name='remark']").val(gridData.remark);
            modal.find("[name='amount']").val(gridData.amount);
            $("#feeScale").val('');
            $(".status").bootstrapSwitch('state', true);
        });
        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.fastQueryParameters['lk_u.user_name_or_like_u.mobile_phone'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent
    }
}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});